Skip to content

Fix when_all hang when some children complete before construction#1150

Merged
sicoyle merged 1 commit into
dapr:mainfrom
passuied:fix/when-all-precompleted-counter-reset
Jul 14, 2026
Merged

Fix when_all hang when some children complete before construction#1150
sicoyle merged 1 commit into
dapr:mainfrom
passuied:fix/when-all-precompleted-counter-reset

Conversation

@passuied

Copy link
Copy Markdown
Contributor

Fixes #1149

Description

WhenAllTask.__init__ was resetting _completed_tasks / _failed_tasks after CompositeTask.__init__ had already counted children that were complete at construction time. That drops early completions, so deferred when_all(children) hangs forever when some but not all children finished before when_all was built.

Changes

  • Stop resetting counters in WhenAllTask.__init__ (keep empty-list fast path)
  • Add unit tests for partial pre-completion, all pre-completion, and when_any([when_all, timeout])

Test plan

  • uv run pytest tests/ext/workflow/durabletask/test_task.py
  • CI green

RELEASE NOTE: FIX Bug causing when_all to hang when some child tasks complete before when_all is constructed

Made with Cursor

WhenAllTask.__init__ was resetting _completed_tasks after CompositeTask
had already counted pre-completed children, so deferred when_all hung
forever in the partial-completion case.

Signed-off-by: Patrick Assuied <patrick.assuied@elationhealth.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a durabletask when_all(children) hang that occurs when some (but not all) child tasks complete before the WhenAllTask is constructed (deferred fan-in). It aligns WhenAllTask’s construction behavior with CompositeTask’s existing “count pre-completed children” initialization logic and adds regression coverage to prevent reintroduction.

Changes:

  • Stop resetting WhenAllTask’s _completed_tasks / _failed_tasks after CompositeTask.__init__ has already accounted for pre-completed children.
  • Add unit tests covering partial pre-completion, full pre-completion, and when_any([when_all(children), timeout]) interaction.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
dapr/ext/workflow/_durabletask/task.py Removes the counter reset in WhenAllTask.__init__ so pre-completed children are retained and when_all can complete correctly.
tests/ext/workflow/durabletask/test_task.py Adds regression tests for deferred when_all with pre-completed children and composition with when_any.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.84%. Comparing base (34136f2) to head (0de8299).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1150      +/-   ##
==========================================
+ Coverage   82.76%   82.84%   +0.08%     
==========================================
  Files         123      123              
  Lines       10123    10121       -2     
==========================================
+ Hits         8378     8385       +7     
+ Misses       1745     1736       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sicoyle sicoyle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing, thank you!!!

@sicoyle sicoyle added this pull request to the merge queue Jul 14, 2026
Merged via the queue into dapr:main with commit 49eeda9 Jul 14, 2026
23 of 24 checks passed
dapr-bot added a commit that referenced this pull request Jul 14, 2026
…1150) (#1151)

WhenAllTask.__init__ was resetting _completed_tasks after CompositeTask
had already counted pre-completed children, so deferred when_all hung
forever in the partial-completion case.



(cherry picked from commit 49eeda9)

Signed-off-by: Patrick Assuied <patrick.assuied@elationhealth.com>
Signed-off-by: dapr-bot <dapr-bot@users.noreply.github.com>
Co-authored-by: Patrick Assuied <patrick.assuied@elationhealth.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

when_all hangs when some children complete before when_all is constructed

5 participants